home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / TREETAG.PY < prev    next >
Encoding:
Python Source  |  2000-08-23  |  23.2 KB  |  688 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. """Rendering object hierarchies as Trees
  65. """
  66. __rcs_id__='$Id: TreeTag.py,v 1.42.8.1 2000/08/23 20:50:37 brian Exp $'
  67. __version__='$Revision: 1.42.8.1 $'[11:-2]
  68.  
  69. from DocumentTemplate.DT_Util import *
  70. from DocumentTemplate.DT_String import String
  71.  
  72. from string import join, split, rfind, find, translate
  73. from urllib import quote, unquote
  74. from zlib import compress, decompress
  75. from binascii import b2a_base64, a2b_base64
  76.  
  77. tbl=join(map(chr, range(256)),'')
  78. tplus=tbl[:ord('+')]+'-'+tbl[ord('+')+1:]
  79. tminus=tbl[:ord('-')]+'+'+tbl[ord('-')+1:]
  80.  
  81. class Tree:
  82.     name='tree'
  83.     blockContinuations=()
  84.     expand=None
  85.  
  86.     def __init__(self, blocks):
  87.         tname, args, section = blocks[0]
  88.         args=parse_params(args, name=None, expr=None, nowrap=1, 
  89.                           expand=None, leaves=None,
  90.                           header=None, footer=None,
  91.                           branches=None, branches_expr=None,
  92.                           sort=None, reverse=1, skip_unauthorized=1,
  93.                           id=None, single=1, url=None,
  94.                           # opened_decoration=None,
  95.                           # closed_decoration=None,
  96.                           # childless_decoration=None,
  97.                           assume_children=1,
  98.                           urlparam=None)
  99.         has_key=args.has_key
  100.  
  101.         if has_key('') or has_key('name') or has_key('expr'):
  102.             name,expr=name_param(args,'tree',1)
  103.  
  104.             if expr is not None: args['expr']=expr
  105.             elif has_key(''): args['name']=name
  106.         else: name='a tree tag'
  107.  
  108.         if has_key('branches_expr'):
  109.             if has_key('branches'):
  110.                 raise ParseError, _tm(
  111.                     'branches and  and branches_expr given', 'tree')
  112.             args['branches_expr']=VSEval.Eval(
  113.                 args['branches_expr'], expr_globals).eval
  114.         elif not has_key('branches'): args['branches']='tpValues'
  115.  
  116.         if not has_key('id'): args['id']='tpId'
  117.         if not has_key('url'): args['url']='tpURL'
  118.         if not has_key('childless_decoration'):
  119.             args['childless_decoration']=''
  120.         
  121.         self.__name__ = name
  122.         self.section=section.blocks
  123.         self.args=args
  124.             
  125.  
  126.     def render(self,md):
  127.         args=self.args
  128.         have=args.has_key
  129.  
  130.         if have('name'): v=md[args['name']]
  131.         elif have('expr'): v=args['expr'].eval(md)
  132.         else: v=md.this
  133.         return tpRender(v,md,self.section, self.args)
  134.  
  135.     __call__=render
  136.  
  137. String.commands['tree']=Tree
  138.  
  139. pyid=id # Copy builtin
  140.  
  141. def tpRender(self, md, section, args,
  142.              simple_type={type(''):0, type(1):0, type(1.0):0}.has_key):
  143.     """Render data organized as a tree.
  144.  
  145.     We keep track of open nodes using a cookie.  The cookie stored the
  146.     tree state. State should be a tree represented like:
  147.  
  148.       []  # all closed
  149.       ['eagle'], # eagle is open
  150.       ['eagle'], ['jeep', [1983, 1985]]  # eagle, jeep, 1983 jeep and 1985 jeep
  151.  
  152.     where the items are object ids. The state will be converted to a
  153.     compressed and base64ed string that gets unencoded, uncompressed, 
  154.     and evaluated on the other side.
  155.  
  156.     Note that ids used in state need not be connected to urls, since
  157.     state manipulation is internal to rendering logic.
  158.  
  159.     Note that to make eval safe, we do not allow the character '*' in
  160.     the state.
  161.     """
  162.  
  163.     data=[]
  164.  
  165.     idattr=args['id']
  166.     if hasattr(self, idattr):
  167.         id=getattr(self, idattr)
  168.         if not simple_type(type(id)): id=id()            
  169.     elif hasattr(self, '_p_oid'): id=oid(self)
  170.     else: id=pyid(self)
  171.  
  172.     try:
  173.         # see if we are being run as a sub-document
  174.         root=md['tree-root-url']
  175.         url=md['tree-item-url']
  176.         state=md['tree-state']
  177.         diff=md['tree-diff']
  178.         substate=md['-tree-substate-']
  179.         colspan=md['tree-colspan']      
  180.         level=md['tree-level']
  181.  
  182.     except KeyError:
  183.         # OK, we are a top-level invocation
  184.         level=-1
  185.  
  186.         if md.has_key('collapse_all'):
  187.             state=[id,[]],
  188.         elif md.has_key('expand_all'):
  189.             have_arg=args.has_key
  190.             if have_arg('branches'):
  191.                 def get_items(node, branches=args['branches'], md=md):
  192.                     validate=md.validate
  193.                     if validate is None or not hasattr(node, 'aq_acquire'):
  194.                         items=getattr(node, branches)
  195.                     else:
  196.                         items=node.aq_acquire(branches, validate, md)
  197.                     return items()
  198.             elif have_arg('branches_expr'):
  199.                 def get_items(node, branches_expr=args['branches_expr'], md=md):
  200.                     md._push(InstanceDict(node, md))
  201.                     items=branches_expr(md)
  202.                     md._pop()
  203.                     return items
  204.             state=[id, tpValuesIds(self, get_items, args)],
  205.         else:
  206.             if md.has_key('tree-s'):
  207.                 state=md['tree-s']
  208.                 state=decode_seq(state)
  209.                 try:
  210.                     if state[0][0] != id: state=[id,[]],
  211.                 except IndexError: state=[id,[]],
  212.             else: state=[id,[]],
  213.  
  214.             if md.has_key('tree-e'):
  215.                 diff=decode_seq(md['tree-e'])
  216.                 apply_diff(state, diff, 1)
  217.  
  218.             if md.has_key('tree-c'):
  219.                 diff=decode_seq(md['tree-c'])
  220.                 apply_diff(state, diff, 0)
  221.  
  222.         colspan=tpStateLevel(state)
  223.         substate=state
  224.         diff=[]
  225.  
  226.         url=''
  227.         root=md['URL']
  228.         l=rfind(root,'/')
  229.         if l >= 0: root=root[l+1:]
  230.  
  231.     treeData={'tree-root-url': root,
  232.               'tree-colspan': colspan,
  233.               'tree-state': state }
  234.     
  235.     md._push(InstanceDict(self, md))
  236.     md._push(treeData)
  237.  
  238.     try: tpRenderTABLE(self,id,root,url,state,substate,diff,data,colspan,
  239.                        section,md,treeData, level, args)
  240.     finally: md._pop(2)
  241.  
  242.     if state is substate and not (args.has_key('single') and args['single']):
  243.         state=state or ([id],)
  244.         state=encode_seq(state)
  245.         md['RESPONSE'].setCookie('tree-s',state)
  246.  
  247.     return join(data,'')
  248.  
  249. def tpRenderTABLE(self, id, root_url, url, state, substate, diff, data,
  250.                   colspan, section, md, treeData, level=0, args=None,
  251.                   simple_type={type(''):0, type(1):0, type(1.0):0}.has_key,
  252.                   ):
  253.     "Render a tree as a table"
  254.  
  255.     have_arg=args.has_key
  256.     exp=0
  257.  
  258.     if level >= 0:
  259.         urlattr=args['url']
  260.         if urlattr and hasattr(self, urlattr):
  261.             tpUrl=getattr(self, urlattr)
  262.             if not simple_type(type(tpUrl)): tpUrl=tpUrl()            
  263.             url = (url and ('%s/%s' % (url, tpUrl))) or tpUrl
  264.             root_url = root_url or tpUrl
  265.  
  266.     treeData['tree-item-url']=url
  267.     treeData['tree-level']=level
  268.     treeData['tree-item-expanded']=0
  269.     idattr=args['id']
  270.  
  271.     output=data.append
  272.  
  273.     items=None
  274.     if (have_arg('assume_children') and args['assume_children']
  275.         and substate is not state):
  276.         # We should not compute children unless we have to.
  277.         # See if we've been asked to expand our children.
  278.         for i in range(len(substate)):
  279.             sub=substate[i]
  280.             if sub[0]==id:
  281.                 exp=i+1
  282.                 break
  283.         if not exp: items=1
  284.  
  285.     if items is None:
  286.         validate=md.validate
  287.         if have_arg('branches') and hasattr(self, args['branches']):
  288.             if validate is None or not hasattr(self, 'aq_acquire'):
  289.                 items=getattr(self, args['branches'])
  290.             else:
  291.                 items=self.aq_acquire(args['branches'],validate,md)
  292.             items=items()
  293.         elif have_arg('branches_expr'):
  294.             items=args['branches_expr'](md)
  295.  
  296.         if not items and have_arg('leaves'): items=1
  297.  
  298.     if items and items != 1:
  299.  
  300.         if validate is not None:
  301.             unauth=[]
  302.             index=0
  303.             for i in items:
  304.                 try: v=validate(items,items,None,i,md)
  305.                 except: v=0
  306.                 if not v: unauth.append(index)
  307.                 index=index+1
  308.  
  309.             if unauth:
  310.                 if have_arg('skip_unauthorized') and args['skip_unauthorized']:
  311.                     items=list(items)
  312.                     unauth.reverse()
  313.                     for i in unauth: del items[i]
  314.                 else:
  315.                     raise ValidationError, unauth
  316.  
  317.         if have_arg('sort'):
  318.             # Faster/less mem in-place sort
  319.             if type(items)==type(()):
  320.                 items=list(items)
  321.             sort=args['sort']
  322.             size=range(len(items))
  323.             for i in size:
  324.                 v=items[i]
  325.                 k=getattr(v,sort)
  326.                 try:    k=k()
  327.                 except: pass
  328.                 items[i]=(k,v)
  329.             items.sort()
  330.             for i in size:
  331.                 items[i]=items[i][1]
  332.  
  333.         if have_arg('reverse'):
  334.             items=list(items)           # Copy the list
  335.             items.reverse()
  336.  
  337.     diff.append(id)
  338.  
  339.  
  340.     _td_colspan='<TD COLSPAN="%s" NOWRAP></TD>'
  341.     _td_single ='<TD WIDTH="16" NOWRAP></TD>'
  342.  
  343.     sub=None
  344.     if substate is state:
  345.         output('<TABLE CELLSPACING="0">\n')
  346.         sub=substate[0]
  347.         exp=items
  348.     else:
  349.         # Add prefix
  350.         output('<TR>\n')
  351.  
  352.         # Add +/- icon
  353.         if items:
  354.             if level:
  355.                 if level > 3:   output(_td_colspan % (level-1))
  356.                 elif level > 1: output(_td_single * (level-1))
  357.                 output(_td_single)
  358.                 output('\n')
  359.             output('<TD WIDTH="16" VALIGN="TOP" NOWRAP>')
  360.             for i in range(len(substate)):
  361.                 sub=substate[i]
  362.                 if sub[0]==id:
  363.                     exp=i+1
  364.                     break
  365.  
  366.             ####################################
  367.             # Mostly inline encode_seq for speed
  368.             s=compress(str(diff))
  369.             if len(s) > 57: s=encode_str(s)
  370.             else:
  371.                 s=b2a_base64(s)[:-1]
  372.                 l=find(s,'=')
  373.                 if l >= 0: s=s[:l]
  374.             s=translate(s, tplus)
  375.             ####################################
  376.  
  377.             script=md['SCRIPT_NAME']
  378.  
  379.             # Propagate extra args through tree.
  380.             if args.has_key( 'urlparam' ):
  381.                 param = args['urlparam']
  382.                 param = "%s&" % param
  383.             else:
  384.                 param = ""
  385.  
  386.             if exp:
  387.                 treeData['tree-item-expanded']=1
  388.                 output('<A NAME="%s" HREF="%s?%stree-c=%s#%s">'
  389.                        '<IMG SRC="%s/p_/mi" ALT="-" BORDER=0></A>' %
  390.                        (id, root_url, param, s, id, script))
  391.             else:
  392.                 output('<A NAME="%s" HREF="%s?%stree-e=%s#%s">'
  393.                        '<IMG SRC="%s/p_/pl" ALT="+" BORDER=0></A>' %
  394.                        (id, root_url, param, s, id, script))
  395.             output('</TD>\n')
  396.  
  397.         else:
  398.             if level > 2:   output(_td_colspan % level)
  399.             elif level > 0: output(_td_single  * level)
  400.             output(_td_single)
  401.             output('\n')
  402.             
  403.     
  404.         # add item text
  405.         dataspan=colspan-level
  406.         output('<TD%s%s VALIGN="TOP" ALIGN="LEFT">' %
  407.                ((dataspan > 1 and (' COLSPAN="%s"' % dataspan) or ''),
  408.                (have_arg('nowrap') and args['nowrap'] and ' NOWRAP' or ''))
  409.                )
  410.         output(render_blocks(section, md))
  411.         output('</TD>\n</TR>\n')
  412.  
  413.  
  414.     if exp:
  415.  
  416.         level=level+1
  417.         dataspan=colspan-level
  418.         if level > 2:   h=_td_colspan % level
  419.         elif level > 0: h=_td_single  * level
  420.         else: h=''
  421.  
  422.         if have_arg('header'):
  423.             doc=args['header']
  424.             if md.has_key(doc): doc=md.getitem(doc,0)
  425.             else: doc=None
  426.             if doc is not None:
  427.                 output(doc(
  428.                     None, md,
  429.                     standard_html_header=(
  430.                         '<TR>%s<TD WIDTH="16" NOWRAP></TD>'
  431.                         '<TD%s VALIGN="TOP">'
  432.                         % (h,
  433.                            (dataspan > 1 and (' COLSPAN="%s"' % dataspan)
  434.                             or ''))),
  435.                     standard_html_footer='</TD></TR>',
  436.                     ))
  437.             
  438.         if items==1:
  439.             # leaves
  440.             if have_arg('leaves'):
  441.                 doc=args['leaves']
  442.                 if md.has_key(doc): doc=md.getitem(doc,0)
  443.                 else: doc=None
  444.                 if doc is not None:
  445.                     treeData['-tree-substate-']=sub
  446.                     treeData['tree-level']=level
  447.                     md._push(treeData)
  448.                     try: output(doc(
  449.                         None,md,
  450.                         standard_html_header=(
  451.                             '<TR>%s<TD WIDTH="16" NOWRAP></TD>'
  452.                             '<TD%s VALIGN="TOP">'
  453.                             % (h,
  454.                                (dataspan > 1 and
  455.                                 (' COLSPAN="%s"' % dataspan) or ''))),
  456.                         standard_html_footer='</TD></TR>',
  457.                         ))
  458.                     finally: md._pop(1)
  459.         elif have_arg('expand'):
  460.             doc=args['expand']
  461.             if md.has_key(doc): doc=md.getitem(doc,0)
  462.             else: doc=None
  463.             if doc is not None:
  464.                 treeData['-tree-substate-']=sub
  465.                 treeData['tree-level']=level
  466.                 md._push(treeData)
  467.                 try: output(doc(
  468.                     None,md,
  469.                     standard_html_header=(
  470.                         '<TR>%s<TD WIDTH="16" NOWRAP></TD>'
  471.                         '<TD%s VALIGN="TOP">'
  472.                         % (h,
  473.                            (dataspan > 1 and
  474.                             (' COLSPAN="%s"' % dataspan) or ''))),
  475.                     standard_html_footer='</TD></TR>',
  476.                     ))
  477.                 finally: md._pop(1)
  478.         else:
  479.             __traceback_info__=sub, args, state, substate
  480.             ids={}
  481.             for item in items:
  482.                 if hasattr(item, idattr):
  483.                     id=getattr(item, idattr)
  484.                     if not simple_type(type(id)): id=id()
  485.                 elif hasattr(item, '_p_oid'): id=oid(item)
  486.                 else: id=pyid(item)
  487.                 if len(sub)==1: sub.append([])
  488.                 substate=sub[1]
  489.                 ids[id]=1
  490.                 md._push(InstanceDict(item,md))
  491.                 try: data=tpRenderTABLE(
  492.                     item,id,root_url,url,state,substate,diff,data,
  493.                     colspan, section, md, treeData, level, args)
  494.                 finally: md._pop()
  495.                 if not sub[1]: del sub[1]
  496.  
  497.             ids=ids.has_key
  498.             for i in range(len(substate)-1,-1):
  499.                 if not ids(substate[i][0]): del substate[i]
  500.  
  501.         if have_arg('footer'):
  502.             doc=args['footer']
  503.             if md.has_key(doc): doc=md.getitem(doc,0)
  504.             else: doc=None
  505.             if doc is not None:
  506.                 output(doc(
  507.                     None, md,
  508.                     standard_html_header=(
  509.                         '<TR>%s<TD WIDTH="16" NOWRAP></TD>'
  510.                         '<TD%s VALIGN="TOP">'
  511.                         % (h,
  512.                            (dataspan > 1 and (' COLSPAN="%s"' % dataspan)
  513.                             or ''))),
  514.                     standard_html_footer='</TD></TR>',
  515.                     ))
  516.  
  517.     del diff[-1]
  518.     if not diff: output('</TABLE>\n')
  519.  
  520.     return data
  521.  
  522.  
  523. def apply_diff(state, diff, expand):
  524.     if not diff: return
  525.     s=[None, state]
  526.     diff.reverse()
  527.     __traceback_info__=s, diff
  528.     while diff:
  529.         id=diff[-1]
  530.         del diff[-1]
  531.         if len(s)==1: s.append([])
  532.         s=s[1]
  533.         loc=-1
  534.         for i in range(len(s)):
  535.             if s[i][0]==id:
  536.                 loc=i
  537.                 break
  538.  
  539.         if loc >= 0:
  540.             if not diff and not expand:
  541.                 del s[loc]
  542.             else:
  543.                 s=s[loc]
  544.         elif diff or expand:
  545.             s.append([id,[]])
  546.             s=s[-1][1]
  547.             while diff:
  548.                 id=diff[-1]
  549.                 del diff[-1]
  550.                 if diff or expand:
  551.                     s.append([id,[]])
  552.                     s=s[-1][1]
  553.  
  554.  
  555. def encode_seq(state):
  556.     "Convert a sequence to an encoded string"
  557.     state=compress(str(state))
  558.     l=len(state)
  559.  
  560.     if l > 57:
  561.         states=[]
  562.         for i in range(0,l,57):
  563.             states.append(b2a_base64(state[i:i+57])[:-1])
  564.         state=join(states,'')
  565.     else: state=b2a_base64(state)[:-1]
  566.  
  567.     l=find(state,'=')
  568.     if l >= 0: state=state[:l]
  569.     
  570.     state=translate(state, tplus)
  571.     return state
  572.  
  573. def encode_str(state):
  574.     "Convert a sequence to an encoded string"
  575.     l=len(state)
  576.  
  577.     if l > 57:
  578.         states=[]
  579.         for i in range(0,l,57):
  580.             states.append(b2a_base64(state[i:i+57])[:-1])
  581.         state=join(states,'')
  582.     else: state=b2a_base64(state)[:-1]
  583.  
  584.     l=find(state,'=')
  585.     if l >= 0: state=state[:l]
  586.         
  587.     state=translate(state, tplus)
  588.     return state
  589.  
  590. def decode_seq(state):
  591.     "Convert an encoded string to a sequence"
  592.     state=translate(state, tminus)
  593.     l=len(state)
  594.  
  595.     if l > 76:
  596.         states=[]
  597.         j=0
  598.         for i in range(l/76):
  599.             k=j+76
  600.             states.append(a2b_base64(state[j:k]))
  601.             j=k
  602.  
  603.         if j < l:
  604.             state=state[j:]
  605.             l=len(state)
  606.             k=l%4
  607.             if k: state=state+'='*(4-k)
  608.             states.append(a2b_base64(state))
  609.         state=join(states,'')
  610.     else:
  611.         l=len(state)
  612.         k=l%4
  613.         if k: state=state+'='*(4-k)
  614.         state=a2b_base64(state)
  615.  
  616.     state=decompress(state)
  617.     if find(state,'*') >= 0: raise 'Illegal State', state
  618.     try: return list(eval(state,{'__builtins__':{}}))
  619.     except: return []
  620.     
  621.  
  622. def tpStateLevel(state, level=0):
  623.     for sub in state:
  624.         if len(sub)==2: level = max(level, 1+tpStateLevel(sub[1]))
  625.         else: level=max(level,1)
  626.     return level
  627.  
  628. def tpValuesIds(self, get_items, args,
  629.                 simple_type={type(''):0, type(1):0, type(1.0):0}.has_key,
  630.                 ):
  631.     # get_item(node) is a function that returns the subitems of node
  632.  
  633.     # This should build the ids of subitems which are
  634.     # expandable (non-empty). Leaves should never be
  635.     # in the state - it will screw the colspan counting.
  636.     r=[]
  637.     idattr=args['id']
  638.     try:
  639.         try: items=get_items(self)
  640.         except AttributeError: items=()
  641.         for item in items:
  642.             try:
  643.                 if get_items(item):
  644.  
  645.                     if hasattr(item, idattr):
  646.                         id=getattr(item, idattr)
  647.                         if not simple_type(type(id)): id=id()            
  648.                     elif hasattr(item, '_p_oid'): id=oid(item)
  649.                     else: id=pyid(item)
  650.  
  651.                     e=tpValuesIds(item, get_items, args)
  652.                     if e: id=[id,e]
  653.                     else: id=[id]
  654.                     r.append(id)
  655.             except: pass
  656.     except: pass
  657.     return r
  658.  
  659.  
  660. def oid(self):
  661.     return b2a_base64(str(self._p_oid))[:-1]
  662.     
  663.  
  664. #icoSpace='<IMG SRC="Blank_icon" BORDER="0">'
  665. #icoPlus ='<IMG SRC="Plus_icon" BORDER="0">'
  666. #icoMinus='<IMG SRC="Minus_icon" BORDER="0">'
  667.